package com.itheima.tliassystem.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
//@Aspect
public class AspectDemo1 {
    //提取公共的切入点表达式
    @Pointcut("execution(* com.itheima.tliassystem.service.*.*(..))")
    public void haha() {
    }

    ;

    //环绕通知 需要自主调用目标方方达 控制在目标方法的任意位置进行增强
    @Around("haha()")
    public Object around(ProceedingJoinPoint PJP) throws Throwable {
        Object result = null;
        System.out.println("环绕通知前置");
        try {
            result = PJP.proceed();
            System.out.println("环绕通知 返回后增强");
        } catch (Throwable e) {
            System.out.println("环绕通知异常处理");
        } finally {
            System.out.println("环绕通知后置");
        }

        return result;
    }

    //前置通知
    @Before("haha()")
    public void before() {
        System.out.println("前置通知");
    }

    //后置通知
    @After("haha()")
    public void after() {
        System.out.println("后置通知");
    }

    //返回后通知
    @AfterReturning("haha()")
    public void afterReturning() {
        System.out.println("返回后通知");
    }

    //异常后通知
    @AfterThrowing("haha()")
    public void afterThrowing() {
        System.out.println("异常后通知");
    }
}
